function [interval,startIndex,endIndex] = subinterval(x, intStart, intEnd)

    if nargin ~= 3
      error('Invalid number of arguments');
    end
    
     if intStart > intEnd
      error('Interval end must be bigger than interval start');
    end
    
    if(intStart > 0)
        if intStart < length(x)
            startIndex = intStart;
        else
            startIndex = length(x);
        end
    else
        startIndex = 1;
    end
    
    
    
    if(intEnd < length(x))
        endIndex = intEnd;
    else
        endIndex = length(x);
    end
    
    interval = x(startIndex:endIndex);
end
